package com.qiyu.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

/**
 * mybatis-plus 基础实体
 *
 * @author zhangweiwei
 * @date 2020/7/30
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode
public class Entity<T extends Model<?>> extends Model<T> implements Serializable {
    
    private static final long serialVersionUID = 739668778715426461L;
    
    @TableId(value = "id", type = IdType.AUTO)
    @ApiModelProperty("主键")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;
    
    @TableLogic
    @ApiModelProperty(value = "是否删除", hidden = true)
    private Boolean deleted;
    
    @TableField(fill = FieldFill.INSERT)
    @ApiModelProperty("创建时间")
    private Date createTime;
    
    @TableField(update = "now()")
    @ApiModelProperty("修改时间")
    private Date updateTime;
    
    
    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Entity<?> entity = (Entity<?>) o;
        return entity.getId().equals(this.id);
    }
    
}
